package com.igoal.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.igoal.entity.PrivacyEnum;
import com.igoal.entity.PrivacySetting;

@Repository("privacySettingDAO")
public class PrivacySettingDAOImpl extends
		GenericDaoHibernate<PrivacySetting, Integer> implements
		PrivacySettingDAO {

	public PrivacySettingDAOImpl() {
		super(PrivacySetting.class);
	}

	public PrivacySetting getPrivacy(PrivacyEnum level) {
		DetachedCriteria dc = DetachedCriteria.forClass(PrivacySetting.class);
		dc.add(Restrictions.eq("level", level));
		List<PrivacySetting> levels = findByCriteria(dc, 0, 1);

		if (levels != null && levels.size() == 1) {
			return levels.get(0);
		}

		return null;
	}

}
